# -*- coding: utf-8 -*-
"""
@Project: base_python
@File: replacetest.py
@Author: PC
@Date: 2025/06/15
@Description: 
"""
import os

# 设置你的文件夹路径
folder_path = 'E:\张恩民分类'  # 修改成你的文件夹路径

for filename in os.listdir(folder_path):
    # 判断是否为文件且包含下划线和.pdf
    if os.path.isfile(os.path.join(folder_path, filename)) and filename.endswith('.pdf') and '_' in filename:
        # 分割，取第一个部分作为新文件名
        new_name = filename.split('_')[0] + '.pdf'
        old_file = os.path.join(folder_path, filename)
        new_file = os.path.join(folder_path, new_name)
        
        # 重命名文件
        os.rename(old_file, new_file)
        print(f'Renamed: {filename} -> {new_name}')
